<?php

namespace addons\shopro\job;


use app\common\logic\UserLevelLogic;
use think\Db;

class MemberBenefits extends BaseJob
{
    /**
     * 定时任务 每月发放会员奖励金
     * 每月1号凌晨5点执行
     */
    public function sendAwardMoney()
    {
        $levelList = UserLevelLogic::getLevelCfgList();
        foreach ($levelList as $v) {
            if($v['month_award_money'] == 0){
                continue;
            }

            //获取该段位的人员
            $userList = Db::name('user')->field('id')->where(['member_level' => $v['id']])->select();
            if(empty($userList)){
                trace('没有达到等级的用户，等级ID:'.$v['id'], 'debug');
                continue;
            }

            foreach ($userList as $u){
                \app\common\model\User::money($v['month_award_money'], $u['id'], '月度奖励金发放');
            }


        }

        echo date('Y-m-d H:i:s').'月度奖励金发放完毕'.PHP_EOL;
    }
}